<template>
	<view class="cart-container" v-if="cart.length !==0 ">
		<my-address></my-address>
		
		<view class="cart-title">
			<uni-icons type="shop" size="18"></uni-icons>
			<view class="cart-text">购物车</view>
		</view>
		
		
		
		
		<uni-swipe-action>
			<block v-for="(item,i) in cart" :key="i">
				<uni-swipe-action-item :right-options="options" @click="swipeItemClickHandler(item)">
					<my-goods :goods="item" :showRadio="true" @radio-change="clickRadio" :showCount="true"
						@num-change="numChangeHandler"></my-goods>
				</uni-swipe-action-item>
			</block>
		</uni-swipe-action>
		
		<my-settle></my-settle>
	</view>
	<view class="empty-car" v-else>
		<image src="/static/emptyShopCar.jpeg" class="empty-img"></image>
		<text class="tip-text">空空如也</text>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar_badge.js'
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		mixins: [badgeMix],
		data() {
			return {
				options:[{
					text: '删除',
					style: {
						backgroundColor: '#C00000'
					}
				}]
			};
		},
		computed: {
			...mapState('m_cart', ['cart'])
		},
		methods: {
			...mapMutations('m_cart', ['updataGoodsState','updataGoodsCount','removeGoodsById']),
			clickRadio(e) {
				this.updataGoodsState(e)
			},
			numChangeHandler(e) {
				this.updataGoodsCount(e)
			},
			swipeItemClickHandler(goods){
				console.log(goods)
				this.removeGoodsById(goods.goods_id)
			}
		}
	}
</script>

<style lang="scss">
	.cart-container{
		padding-bottom: 50px;
	}
	.cart-title {
		height: 40px;
		display: flex;
		padding-left: 5px;
		align-items: center;
		border-bottom: 1px solid #efefef;

		.cart-text {
			font-size: 14px;
			margin-left: 10px;
		}
	}
	.empty-car{
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 150px;
		.empty-img{
			width: 150px;
			height: 150px;
		}
		.tip-text{
			font-size: 12px;
			color: gray;
			margin-top: 15px;
		}
	}
</style>